home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Diamond Collection
/
The Diamond Collection (Software Vault)(Digital Impact).ISO
/
cdr34
/
onetime.zip
/
CVT.C
next >
Wrap
C/C++ Source or Header
|
1995-04-26
|
3KB
|
171 lines
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#define NUMBERS 10
#define INVOCATION_ERROR 20
#define FILE_ERR 11
#define BUFFERSIZE 8192
#define FILENAME argv[1]
#define TRUE 1
#define FALSE 0
#define NUMCVT 48
#define PARAM_NO 2
#define APOSTROPHE 39
#define DOLLAR_SIGN '$'
const char *Table [NUMBERS] = {
"ZERO",
"ONE",
"TWO",
"THREE",
"FOUR",
"FIVE",
"SIX",
"SEVEN",
"EIGHT",
"NINE"
};
long code( char *filename );
void main( int argc, char **argv )
{
long no;
if( argc != PARAM_NO )
{
printf( "\nForm: cvt FILENAME." );
exit( INVOCATION_ERROR );
}
no = code( FILENAME );
printf( "\n%ld characters converted in the file %s.", no, FILENAME );
}
long code( char *filename )
{
register int c;
long number = 0;
FILE *plaintxt,
*cvtfile;
if( NULL == ( plaintxt = fopen( filename, "r" ) ) )
exit( FILE_ERR );
if( setvbuf( plaintxt, NULL, _IOFBF, BUFFERSIZE ) )
exit( FILE_ERR );
if( NULL == ( cvtfile = fopen( "file.cvt", "w" ) ) )
exit ( FILE_ERR );
if( setvbuf( cvtfile, NULL, _IOFBF, BUFFERSIZE ) )
exit( FILE_ERR );
while( EOF != ( c = fgetc( plaintxt ) ) )
{
if( isdigit( c ) )
{
c -= NUMCVT;
fputs( Table [c], cvtfile );
}
else
if( c == '$' )
fputs( "DOLLARSIGN", cvtfile );
else
if( ispunct( c ) )
switch( c )
{
case '.':
fputs( "PERIOD", cvtfile );
break;
case ',':
fputs( "COMMA", cvtfile );
break;
case ':':
fputs( "COLON", cvtfile );
break;
case ';':
fputs( "SEMICOLON", cvtfile );
break;
case '"':
fputs( "QUOTE", cvtfile );
break;
case '!':
fputs( "EXCLAMATIONPOINT", cvtfile );
break;
case APOSTROPHE:
fputs( "APOSTROPHE", cvtfile );
break;
case '/':
fputs( "SLASH", cvtfile );
break;
case '\\':
fputs( "BACKSLASH", cvtfile );
break;
case '(':
fputs( "LEFTPAREN", cvtfile );
break;
case ')':
fputs( "RIGHTPAREN", cvtfile );
break;
case '*':
fputs( "ASTERISK", cvtfile );
break;
case '-':
fputs( "DASH", cvtfile );
break;
case '&':
fputs( "AMPERSAND", cvtfile );
break;
case '$':
fputs( "DOLLARSIGN", cvtfile );
break;
case '%':
fputs ( "PERCENT", cvtfile );
break;
case '#':
fputs ( "POUNDSIGN", cvtfile );
break;
case '?':
fputs( "QUESTIONMARK", cvtfile );
break;
case '=':
fputs ( "EQUALS", cvtfile );
break;
case '+':
fputs( "PLUS", cvtfile );
break;
}
else
fputc( c, cvtfile );
number++;
}
fcloseall();
return( number );
}